package daos;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import Facade.AcademicoFacade;

import entidades.Endereco;

public class EnderecoDao implements AcademicoFacade<Endereco> {
	static EntityManagerFactory factory = Persistence
			.createEntityManagerFactory("academicoDatabase");

	public Endereco salvar(Endereco endereco) {
		EntityManager manager = factory.createEntityManager();
		manager.persist(endereco);
		manager.getTransaction().begin();
		manager.getTransaction().commit();
		manager.close();
		return endereco;

	}

	public void Excluir(Endereco endereco) {
		EntityManager manager = factory.createEntityManager();
		endereco = manager.find(Endereco.class, endereco.getIdEndereco());
		manager.remove(endereco);
		manager.getTransaction().begin();
		manager.getTransaction().commit();
		manager.close();

	}

	@Override
	public Endereco atualizar(Endereco objeto) {
		// TODO Auto-generated method stub
		return null;
	}

	public Endereco buscarPorId(Class<Endereco> objeto, Long id) {
		EntityManager manager = factory.createEntityManager();
		return manager.find(Endereco.class, id);

	}

	@Override
	public List<Endereco> buscarTodos(Class<Endereco> objeto) {
		// TODO Auto-generated method stub
		return null;
	}

}
